package com.linkai.基础._01_copy;

/**
 * @Description: 对象拷贝
 *                对象拷贝的地址是不同的，也就是说创建了新的对象，
 *                而不是把原对象的地址赋给了一个新的引用变量,这就叫做对象拷贝。
 *                深拷贝和浅拷贝都是对象拷贝
 * @Author: 林凯
 * @Date: 2021/10/29 23:17
 */
public class _02_ObjectCopy {
    public static void main(String[] args) throws CloneNotSupportedException {
        Teacher2 t1 = new Teacher2("JackLin", 21);
        Teacher2 t2 = (Teacher2) t1.clone();
        System.out.println(t1);
        System.out.println(t2);
        /*
            com.linkai.基础._01_copy.Teacher2@74a14482
            com.linkai.基础._01_copy.Teacher2@1540e19d
        * */
    }
}

class Teacher2 implements Cloneable {
    private String name;
    private int age;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public Teacher2(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
